import { createSlice } from '@reduxjs/toolkit'

const initialState = {
  location: {
    name: '公司附近',
    latitude: null,
    longitude: null
  },
  preferences: {
    defaultCuisine: [],
    maxDistance: 2000,  // 默认2公里
    priceRange: []
  }
}

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    updateLocation: (state, action) => {
      state.location = {
        ...state.location,
        ...action.payload
      }
    },
    updatePreferences: (state, action) => {
      state.preferences = {
        ...state.preferences,
        ...action.payload
      }
    }
  }
})

export const { updateLocation, updatePreferences } = userSlice.actions

export default userSlice.reducer 